const app = getApp();
Page({
  data: {
    list:[],
  },
  onLoad(options){
    let that = this;
    that.setData({
      options: options
    })
  },
  onShow: function () {
    this.getInfo();
  },
  getInfo(){
    let that = this;
    app.request('invoices/invoicesList', {}, 'GET', false, function (res) {
      that.setData({
        pageShow: true,
        list: res.data.data || [],
      })
    })
  },
  skipPage(e){
    app.skipPage(e);
  },
  del(e){
    let that = this;
    wx.showModal({
      title: '',
      content: '确定要删除吗?',
      showCancel: true,
      success: function (res) {
        if (res.confirm) {
          let invoices_id = e.currentTarget.dataset.id;
          app.request('invoices/delete', { invoices_id }, 'GET', false, function (res) {
            wx.showToast({
              title: '已删除',
            })
            that.getInfo();
          })
        }
      }
    })
  },
  toback(e){
    let that = this;
    if (that.data.options.from == 'order') {
      let index = e.currentTarget.dataset.index;
      let list = that.data.list;
      wx.setStorageSync('invoiceChoose', list[index]);
      wx.navigateBack({
        delta: 1,
      })
    }
  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {
    return{
      path: '/pages/index/index'
    }
  }
})